package com.gimi.cloud.jimi.dao.dao.homePage;

import com.gimi.cloud.jimi.dao.myMapper.MyMapper;
import com.gimi.cloud.jimi.dto.app.ColumnDTO;
import com.gimi.cloud.jimi.entity.app.ColumnEntity;
import org.apache.ibatis.annotations.*;

import java.util.List;
import org.apache.ibatis.annotations.Select;


/**
 * Created by shazhiwei on 2017/12/27.
 */
public interface ColumnDao extends MyMapper<ColumnEntity> {
    /**
     * 栏目列表
     */
    @Select("SELECT column_id,page_id,column_name,column_desc,column_sort,column_status FROM jimi_column WHERE column_status = 1 AND page_id = #{pageId} ORDER BY column_sort DESC;")
    List<ColumnDTO> columnList(@Param(value = "pageId") Integer pageId);

    /**
     * 获得栏目列表（分页），支持条件查询
     * @param columnDTO
     * @return
     */
    List<ColumnDTO> queryPageList(ColumnDTO columnDTO);

    /**
     * 禁用或者启用
     * @param columnDTO
     * @return
     */
    @Update("update jimi_column set column_status = #{columnStatus} where column_id =#{columnId}")
    Integer deleteColumn(ColumnDTO columnDTO);

    /**
     * 通过名字查询栏目
     * @param columnDTO
     * @return
     */
    @Select("SELECT * FROM jimi_column WHERE column_name = #{columnName} LIMIT 1")
    ColumnEntity selectColumnByName(ColumnDTO columnDTO);

    //这个方法利用mybatis提供的关联查询(效率较差,弃用)
    /*@Select("select * from jimi_column")
    @Results({
            @Result(id=true,property="id",column="id"),
            @Result(property="columnId",column="column_id"),
            @Result(property="adName",column="ad_name"),
            @Result(property="adStatus",column="ad_status"),
            @Result(property="publish_time",column="publish_time"),
            @Result(property="end_time",column="end_time"),
            @Result(property="publish_man",column="publish_man"),
            @Result(property="modify_time",column="modify_time"),
            @Result(property="type",column="type"),
            @Result(property="coment",column="coment"),
            @Result(property="pageId",column="page_id"),
            @Result(property="imgUrl",column="img_url"),
            @Result(property="positionNum",column="position_num"),
            @Result(property="adClass",column="ad_class"),
            @Result(property="adObject",column="ad_object"),
            @Result(property="title",column="title"),
            @Result(property="subTitle",column="sub_title"),
            @Result(property="price",column="price"),
            @Result(property="originalPrice",column="original_price"),

            @Result(property="adList",column="column_id",javaType=List.class,
                    many=@Many(select="com.gimi.cloud.jimi.dao.dao.homePage.AdDao.getByColumnId"))
    })
    List<ColumnDTO> homePage();*/
}
